<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>arguments</title>
    </head>
    <body>
        <script type="text/javascript">
            function hello(a, b, c, d) {
                console.log('hello() -----');
                console.log('arguments ', arguments);
                console.log('a,b,c,d ', a, b, c, d);
            }

            function name(...args) {
                console.log('name() -----');
                console.log('args ', args);
                console.log('arguments ', arguments);

                let [aa, ...bcd] = [...arguments];
                console.log('[aa, ...bcd] ', aa, bcd);

                // 会改变后面 arguments 原数组
                // let firstArgs = [].shift.call(arguments);
                // console.log('firstArgs ', firstArgs, [...arguments]);

                let afterArgs = [].slice.call(arguments, 1);
                console.log('afterArgs ', afterArgs);

                hello(...arguments);

                // 1.用Array.prototype.slice实现
                var arr1 = Array.prototype.slice.call(arguments, 0);
                console.log('arr1 ', arr1);

                // 2.用空数组实现
                var arr2 = [].slice.call(arguments, 0);
                console.log('arr2 ', arr2);

                // 3.遍历arguments实现
                var arg3 = [];
                for (var i = 0; i < arguments.length; i++) {
                    arg3.push(arguments[i]);
                }
                console.log('arg3 ', arg3);

                // 4.遍历arguments实现
                var arg4 = Array.from(arguments);
                console.log('arg4 ', arg4);
            }
            name('a', 'b', 'c', 'd');
        </script>
    </body>
</html>
